#include <stdio.h>
#include <pthread.h>

typedef struct __account_t {
	pthread_mutex_t mut;
	double balance;
	int login_cnt;
} account_t;

void withdraw(account_t *acc, double amt) {
	pthread_mutex_lock(&acc->mut);
	if (acc->balance > amt) {
    	acc->balance -= amt;
    }
	pthread_mutex_unlock(&acc->mut);
}

void login_stat(account_t *acc) {
	pthread_mutex_lock(&acc->mut);	
	acc->login_cnt++;
	pthread_mutex_unlock(&acc->mut);
}

int main() {
	account_t acc;
	acc.balance = 100;
	
	pthread_mutex_init(&acc.mut, NULL);	
	
	login_stat(&acc);
	withdraw(&acc, 20);
	printf("余额：%f\n", acc.balance);	
}
